<?php

require_once APPPATH . 'libraries/PartnerParser/Kinoperez.php';

/**
 * KinoperezOnline парсер
 *
 * @author Gennadiy Kozlenko
 */
class PartnerParser_KinoperezOnline extends PartnerParser_Kinoperez {

    /**
     * Parse partners link
     */
    public function parse() {
        $content = $this->getContent($this->xmlLink);
        if (!empty($content)) {
            $xml = @simplexml_load_string($content);
            if ($xml) {
                $films = $xml->xpath('/files_list/film');
                if ($films) {
                    foreach ($films as $film) {
                        $externalId = (string) $film['id'];
                        $entry = new VideoEntry();
                        $title = trim(stripslashes((string) $film->title));
                        $entry->setTitle($title);
                        $origTitle = trim(stripslashes((string) $film->title_en));
                        if ($origTitle != $title) {
                            $entry->setOrigTitle($origTitle);
                        }
                        $entry->setYear((int) $film->year);
                        $videos = $this->searchVideos($entry);
                        foreach ($videos as $idVideo) {
                            $this->registerPartner($idVideo, $this->idPartner, $externalId);
                        }
                    }
                } else {
                    $this->obj->log('Error: Empty movies list');
                }
            } else {
                $this->obj->log('Error: Cannot parse XML');
            }
        } else {
            $this->obj->log('Error: Empty content');
        }
    }

}